Refer to the following code:
// SPDX-License-Identifier: SOME IDENTIFIER
pragma solidity ^0.8.10;
contract PureFunctionTest {
uint c;
function updateLocalVariables(uint a, uint b) public pure
returns (uint) {
return a + b ;
}
function updateStateVariable(uint x, uint y) public {
c = updateLocalVariables(x, y);
}
}
We should use these two keywords, pure or view, as much as
possible in the code for the optimal usage of gas.
2.5.17 Fallback Function
A contract can optionally have one fallback function of a particular
specification. The fallback function must have no arguments and no
return statement, and must have external visibility. It can be marked
as payable to receive the Ethers.
Refer to the following code:
// SPDX-License-Identifier: SOME IDENTIFIER
pragma solidity ^0.8.10;
contract CalledContract {
fallback() external payable {}
}
contract CallerContract {
function callSink(CalledContract calledContract) public
returns (bool) {
address payable calledContractPayable =
address(calledContract);